<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  

  
  <title>1至7天内容复习 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  
  
  <meta name="description" content="1 dubbox1.1 注册中心 Zookeeper安装步骤，如何启动 1.2 服务提供者在服务类添加@Service注解，所属包为：com.alibaba.dubbo.config.annotation.Service 配置文件： 1234567891011    &amp;lt;dubbo:protocol name=&quot;dubbo&quot; port=&quot;20884&quot;&amp;gt;&amp;lt;/dubbo:protoco">
<meta name="keywords" content="品优购">
<meta property="og:type" content="article">
<meta property="og:title" content="1至7天内容复习">
<meta property="og:url" content="http://yoursite.com/2018/12/08/1至7天内容复习/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="1 dubbox1.1 注册中心 Zookeeper安装步骤，如何启动 1.2 服务提供者在服务类添加@Service注解，所属包为：com.alibaba.dubbo.config.annotation.Service 配置文件： 1234567891011    &amp;lt;dubbo:protocol name=&quot;dubbo&quot; port=&quot;20884&quot;&amp;gt;&amp;lt;/dubbo:protoco">
<meta property="og:locale" content="default">
<meta property="og:updated_time" content="2018-12-22T08:44:41.524Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="1至7天内容复习">
<meta name="twitter:description" content="1 dubbox1.1 注册中心 Zookeeper安装步骤，如何启动 1.2 服务提供者在服务类添加@Service注解，所属包为：com.alibaba.dubbo.config.annotation.Service 配置文件： 1234567891011    &amp;lt;dubbo:protocol name=&quot;dubbo&quot; port=&quot;20884&quot;&amp;gt;&amp;lt;/dubbo:protoco">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/images/default-avatar.jpeg">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
  <link rel="stylesheet" href="/css/highlight.css">
</head>
</html>
<body>
  <div id="fullpage" class="mobile-nav-right">
    
      <div id="wrapper" title="图片来自网络">
    
    
      <header id="header">
  <div id="nav-toggle" class="nav-toggle"></div>
  <div class="head-box global-width">
    <nav class="nav-box nav-right">
      
        <a class="nav-item" href="/" title="">首页</a>
      
        <a class="nav-item" href="/archives" title="">归档</a>
      
    </nav>
  </div>
</header>
      <div id="middlecontent" title class="global-width sidebar-right">
        <section id="main"><article id="post-1至7天内容复习" class="article global-container article-type-post" itemscope="" itemprop="blogPost">
  
    <header class="article-header">
      
  
    <h1 class="article-title" itemprop="name">
      1至7天内容复习
    </h1>
  

    </header>
  
  <div class="article-meta">
    <a href="/2018/12/08/1至7天内容复习/" class="article-date">
  <time datetime="2018-12-08T07:14:03.000Z" itemprop="datePublished">2018-12-08</time>
</a>
    
    
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/品优购/">品优购</a></li></ul>

  </div>
  
    <span id="busuanzi_container_page_pv">
      本文总阅读量<span id="busuanzi_value_page_pv"></span>次
    </span>
  

  <div class="article-inner">
    
    <div class="article-content article-content-doorframe" itemprop="articleBody">
      
        <h2 id="1-dubbox"><a href="#1-dubbox" class="headerlink" title="1 dubbox"></a>1 dubbox</h2><h3 id="1-1-注册中心-Zookeeper"><a href="#1-1-注册中心-Zookeeper" class="headerlink" title="1.1 注册中心 Zookeeper"></a>1.1 注册中心 Zookeeper</h3><p>安装步骤，如何启动</p>
<h3 id="1-2-服务提供者"><a href="#1-2-服务提供者" class="headerlink" title="1.2 服务提供者"></a>1.2 服务提供者</h3><p>在服务类添加@Service注解，所属包为：com.alibaba.dubbo.config.annotation.Service</p>
<p>配置文件：</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="XML"><figure class="iseeu highlight /xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">    <span class="tag">&lt;<span class="name">dubbo:protocol</span> <span class="attr">name</span>=<span class="string">"dubbo"</span> <span class="attr">port</span>=<span class="string">"20884"</span>&gt;</span><span class="tag">&lt;/<span class="name">dubbo:protocol</span>&gt;</span> 指定客户端连接端口</span><br><span class="line">	<span class="tag">&lt;<span class="name">dubbo:application</span> <span class="attr">name</span>=<span class="string">"pinyougou-search-service"</span>/&gt;</span> 指定应用名称  </span><br><span class="line">    <span class="tag">&lt;<span class="name">dubbo:registry</span> <span class="attr">address</span>=<span class="string">"zookeeper://192.168.25.135:2181"</span>/&gt;</span> 连接注册中心</span><br><span class="line">    <span class="tag">&lt;<span class="name">dubbo:annotation</span> <span class="attr">package</span>=<span class="string">"com.pinyougou.search.service.impl"</span> /&gt;</span> 设置服务类所在得包</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">注：</span><br><span class="line"></span><br><span class="line">```xml</span><br><span class="line">  <span class="tag">&lt;<span class="name">dubbo:protocol</span> <span class="attr">name</span>=<span class="string">"dubbo"</span> <span class="attr">port</span>=<span class="string">"20884"</span>&gt;</span><span class="tag">&lt;/<span class="name">dubbo:protocol</span>&gt;</span> </span><br><span class="line"> 	该端口默认是20880 若在一台机器上运行多个服务提供者，则需要给每个提供者设置一个不同的端口</span><br></pre></td></tr></table></figure></div>
<h3 id="1-3-服务消费者"><a href="#1-3-服务消费者" class="headerlink" title="1.3 服务消费者"></a>1.3 服务消费者</h3><p>在控制器类添加@Reference注解，类似原来的自动注入，区别在于此注解注入的是远程得实现</p>
<p>配置文件：</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="XML"><figure class="iseeu highlight /xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">   <span class="tag">&lt;<span class="name">dubbo:application</span> <span class="attr">name</span>=<span class="string">"pinyougou-search-web"</span> /&gt;</span> 指定应用名称  </span><br><span class="line"><span class="tag">&lt;<span class="name">dubbo:registry</span> <span class="attr">address</span>=<span class="string">"zookeeper://192.168.25.135:2181"</span>/&gt;</span> 连接注册中心</span><br><span class="line"><span class="tag">&lt;<span class="name">dubbo:annotation</span> <span class="attr">package</span>=<span class="string">"com.pinyougou.search.controller"</span> /&gt;</span>  设置控制器类所在得包</span><br></pre></td></tr></table></figure></div>
<h3 id="1-4-采用配置的方式获取远程bean"><a href="#1-4-采用配置的方式获取远程bean" class="headerlink" title="1.4 采用配置的方式获取远程bean"></a>1.4 采用配置的方式获取远程bean</h3><div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="XML"><figure class="iseeu highlight /xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">   <span class="tag">&lt;<span class="name">dubbo:application</span> <span class="attr">name</span>=<span class="string">"pinyougou-shop-web"</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dubbo:registry</span> <span class="attr">address</span>=<span class="string">"zookeeper://192.168.25.135:2181"</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dubbo:reference</span> <span class="attr">id</span>=<span class="string">"sellerService"</span>         <span class="attr">interface</span>=<span class="string">"com.pinyougou.sellergoods.service.SellerService"</span>&gt;</span><span class="tag">&lt;/<span class="name">dubbo:reference</span>&gt;</span></span><br></pre></td></tr></table></figure></div>
<h2 id="2-前端框架-AngularJS"><a href="#2-前端框架-AngularJS" class="headerlink" title="2 前端框架 AngularJS"></a>2 前端框架 AngularJS</h2><h3 id="1-1-表达式"><a href="#1-1-表达式" class="headerlink" title="1.1 表达式"></a>1.1 表达式</h3><p>写法：</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="PLAIN"><figure class="iseeu highlight /plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123;&#123;&#125;&#125;</span><br></pre></td></tr></table></figure></div>
<h3 id="1-2-指令"><a href="#1-2-指令" class="headerlink" title="1.2 指令"></a>1.2 指令</h3><ol>
<li><p><strong>ng-app</strong> ：指定当前模块名称，设置ag的范围 在一个html中只能出现一次</p>
</li>
<li><p><strong>ng-controller</strong>：指定当前模块的控制器</p>
</li>
<li><p><strong>ng-init</strong>：初始化加载（变量 函数）</p>
</li>
<li><p><strong>ng-model</strong>：绑定变量</p>
</li>
<li><p><strong>ng-repeat</strong>：循环 xx in list 如果循环数组时有相同的元素  需要添加 xx in list track by $index</p>
</li>
<li><p><strong>ng-click</strong>：点击事件（调用的方法，修改变量的值）</p>
</li>
<li><p><strong>ng-if</strong>:判断当条件成立时，显示div或span里得内容</p>
</li>
<li><p><strong>ng-options</strong>:指定下拉列表(select)得数据来源，语法格式如下：</p>
<p>集合成员.值属性 as 集合成员.文本属性 for 集合成员 in 集合</p>
<p>循环select中的option   bean.XX as bean.XXX  for bean in list   bean.XX option的value（绑定之后所能获取的内容） bean.XXX 用户可以看到的内容option的text</p>
</li>
<li><p><strong>ng-checked</strong>:设置checkbox是否选中 （ng-checked=”true” 选中 ng-checked=”false” 未选中 ）</p>
</li>
<li><p><strong>ng-true-value</strong>:设置checkbox选中的值</p>
</li>
<li><p><strong>ng-false-value</strong>:设置checkbox未选中的值</p>
</li>
<li><p>ng-bind-html:绑定htm并且显示</p>
</li>
</ol>
<h3 id="1-3快捷方法"><a href="#1-3快捷方法" class="headerlink" title="1.3快捷方法"></a>1.3快捷方法</h3><ul>
<li>创建自定义模块 app</li>
</ul>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="JS"><figure class="iseeu highlight /js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> app = angular.module(<span class="string">"pinyougou"</span>, []);</span><br><span class="line"><span class="keyword">var</span> app = angular.module(<span class="string">"pinyougou"</span>, [ <span class="string">'pagination'</span> ]);</span><br></pre></td></tr></table></figure></div>
<ul>
<li>定义控制器 controller</li>
</ul>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="JS"><figure class="iseeu highlight /js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">app.controller(<span class="string">"baseController"</span>, <span class="function"><span class="keyword">function</span>(<span class="params">$scope</span>) </span>&#123;&#125;</span><br></pre></td></tr></table></figure></div>
<ul>
<li>定义服务 service</li>
</ul>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="JS"><figure class="iseeu highlight /js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">app.service(<span class="string">'contentService'</span>,<span class="function"><span class="keyword">function</span>(<span class="params">$http</span>)</span>&#123;&#125;</span><br></pre></td></tr></table></figure></div>
<ul>
<li>创建过滤器 filter（之后的课程中的讲解内容）</li>
</ul>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="JS"><figure class="iseeu highlight /js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">app.filter(<span class="string">'TrustHTML'</span>,[<span class="string">'$sce'</span>,<span class="function"><span class="keyword">function</span>(<span class="params">$sce</span>)</span>&#123;&#125;])  使用的时候 需要加一个 “|”</span><br></pre></td></tr></table></figure></div>
<h3 id="1-4内置服务"><a href="#1-4内置服务" class="headerlink" title="1.4内置服务"></a>1.4内置服务</h3><ul>
<li>$http:发送请求</li>
</ul>
<p>get请求</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="JS"><figure class="iseeu highlight /js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">$http.get(URL).success(</span><br><span class="line">    <span class="function"><span class="keyword">function</span>(<span class="params">responce</span>)</span>&#123;</span><br><span class="line">    	<span class="comment">//处理响应结果</span></span><br><span class="line">	&#125;</span><br><span class="line">).error(</span><br><span class="line">    <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">   		<span class="comment">//处理404 500等无法调取到服务器的情况</span></span><br><span class="line">	&#125;</span><br><span class="line">);</span><br></pre></td></tr></table></figure></div>
<p>post请求</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="JS"><figure class="iseeu highlight /js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$http(&#123;</span><br><span class="line">    url:<span class="string">'../upload.do'</span>,</span><br><span class="line">    method:<span class="string">'post'</span>,</span><br><span class="line">    data:formdata,</span><br><span class="line">    headers:&#123;<span class="string">'Content-Type'</span>:<span class="literal">undefined</span>&#125;,<span class="comment">//设置头文件 设置不使用json提交</span></span><br><span class="line">    transformRequest: angular.identity<span class="comment">//表单2进制序列化</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure></div>
<ul>
<li><p>$location：地址栏服务</p>
<p>获取参数：</p>
</li>
</ul>
<p>​    $location.search()—&gt;所有页面url中的参数 </p>
<p>​    $location.search()[param]—&gt;获取特定的页面url中的参数</p>
<ul>
<li>$controller</li>
</ul>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="JS"><figure class="iseeu highlight /js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$controller(<span class="string">'baseController'</span>,&#123;<span class="attr">$scope</span>:$scope&#125;); <span class="comment">//继承</span></span><br></pre></td></tr></table></figure></div>
<ul>
<li>$sce：将html 字符串 解析浏览器可识别的html trustAsHtml </li>
</ul>
<p>不属于内置服务的</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="PLAIN"><figure class="iseeu highlight /plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$scope：系统变量</span><br><span class="line"></span><br><span class="line">$watch：       </span><br><span class="line"></span><br><span class="line">	$scope的内置方法</span><br></pre></td></tr></table></figure></div>
<h3 id="1-5分页"><a href="#1-5分页" class="headerlink" title="1.5分页"></a>1.5分页</h3><p>引入分页模块</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="HTML"><figure class="iseeu highlight /html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"../plugins/angularjs/pagination.js"</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">"stylesheet"</span> <span class="attr">href</span>=<span class="string">"../plugins/angularjs/pagination.css"</span>&gt;</span></span><br></pre></td></tr></table></figure></div>
<p>在页面添加分页模块</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="JS"><figure class="iseeu highlight /js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//分页控件配置 </span></span><br><span class="line">		<span class="comment">//currentPage：当前页，totalItems：总记录数，</span></span><br><span class="line">		<span class="comment">//itemsPerPage：每页条数，perPageOptions：分页选项</span></span><br><span class="line">		<span class="comment">//onChange：当页码发生改变触发的方法</span></span><br><span class="line">		$scope.paginationConf = &#123;</span><br><span class="line">			<span class="comment">//currentPage : 1,</span></span><br><span class="line">			<span class="comment">//totalItems : 10,</span></span><br><span class="line">			itemsPerPage : <span class="number">10</span>,</span><br><span class="line">			perPageOptions : [ <span class="number">10</span>, <span class="number">20</span>, <span class="number">30</span>, <span class="number">40</span>, <span class="number">50</span> ],</span><br><span class="line">			onChange : <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">				当页面改变执行的方法</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;;</span><br></pre></td></tr></table></figure></div>
<p> 构建app模块时引入pagination模块</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="PLAIN"><figure class="iseeu highlight /plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">var app = angular.module(&quot;pinyougou&quot;, [ &apos;pagination&apos; ]);</span><br></pre></td></tr></table></figure></div>
<h2 id="3-springSecurity"><a href="#3-springSecurity" class="headerlink" title="3 springSecurity"></a>3 springSecurity</h2><h3 id="1-1实现步骤"><a href="#1-1实现步骤" class="headerlink" title="1.1实现步骤"></a>1.1实现步骤</h3><ol>
<li>引入依赖</li>
<li>在web添加过滤器 springSecurityFilterChain</li>
<li>编写配置文件</li>
</ol>
<h3 id="1-2-配置文件"><a href="#1-2-配置文件" class="headerlink" title="1.2 配置文件"></a>1.2 配置文件</h3><p>页面拦截规则</p>
<ul>
<li>http</li>
</ul>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="XML"><figure class="iseeu highlight /xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">intercept-url</span> <span class="attr">pattern</span>=<span class="string">"/**"</span> <span class="attr">access</span>=<span class="string">"ROLE_SELLER"</span>/&gt;</span></span><br></pre></td></tr></table></figure></div>
<p>配置拦截路径，根目录下的所有资源，必须有ROLE_SELLER角色才可以访问。角色名称必须是ROLE_开头</p>
<p>让某个url不拦截</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="XML"><figure class="iseeu highlight /xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">http</span> <span class="attr">pattern</span>=<span class="string">"/img/**"</span> <span class="attr">security</span>=<span class="string">"none"</span>&gt;</span><span class="tag">&lt;/<span class="name">http</span>&gt;</span></span><br></pre></td></tr></table></figure></div>
<ul>
<li><p><form-login> 表单相关配置</form-login></p>
<p>如果按照默认配置：</p>
<p>框架会自动生成一个 “/login” 后端地址（注意：必须post提交）</p>
<p>表单的用户名为username 密码为password</p>
<p>login-page：制定登陆页</p>
<p>default-target-url：登陆成功后跳转的页面</p>
<p>authentication-failure-url：登陆失败跳转的页面</p>
</li>
<li><p>安全管理</p>
<p>以下配置：指定一个用户admin 密码是123456 角色是 ROLE_ADMIN</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="XML"><figure class="iseeu highlight /xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 认证管理器 --&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">authentication-manager</span>&gt;</span></span><br><span class="line">		</span><br><span class="line">			<span class="tag">&lt;<span class="name">authentication-provider</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">user-service</span>&gt;</span></span><br><span class="line">					<span class="tag">&lt;<span class="name">user</span> <span class="attr">name</span>=<span class="string">"admin"</span> <span class="attr">password</span>=<span class="string">"123456"</span> <span class="attr">authorities</span>=<span class="string">"ROLE_ADMIN"</span>/&gt;</span></span><br><span class="line">				<span class="tag">&lt;/<span class="name">user-service</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;/<span class="name">authentication-provider</span>&gt;</span></span><br><span class="line">			</span><br><span class="line">		<span class="tag">&lt;/<span class="name">authentication-manager</span>&gt;</span></span><br></pre></td></tr></table></figure></div>
<p>以下配置为：读取数据库中用户的数据</p>
</li>
</ul>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="XML"><figure class="iseeu highlight /xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">authentication-manager</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">authentication-provider</span> <span class="attr">user-service-ref</span>=<span class="string">"userDetailsServiceImpl"</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">password-encoder</span> <span class="attr">ref</span>=<span class="string">"bcryptPasswordEncoder"</span>&gt;</span><span class="tag">&lt;/<span class="name">password-encoder</span>&gt;</span>				<span class="tag">&lt;/<span class="name">authentication-provider</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;/<span class="name">authentication-manager</span>&gt;</span></span><br><span class="line">		<span class="comment">&lt;!-- 认证类 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">beans:bean</span> <span class="attr">id</span>=<span class="string">"userDetailsServiceImpl"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">class</span>=<span class="string">"com.pinyougou.shop.service.UserDetailsServiceImpl"</span> &gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">beans:property</span> <span class="attr">name</span>=<span class="string">"sellerService"</span> <span class="attr">ref</span>=<span class="string">"sellerService"</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">beans:bean</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">beans:bean</span> <span class="attr">id</span>=<span class="string">"bcryptPasswordEncoder"</span> <span class="attr">class</span>=<span class="string">"org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"</span>&gt;</span><span class="tag">&lt;/<span class="name">beans:bean</span>&gt;</span></span><br></pre></td></tr></table></figure></div>
<p>  需要自定义认证类：</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="JAVA"><figure class="iseeu highlight /java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * </span></span><br><span class="line"><span class="comment"> * &lt;p&gt;Title: UserDetailsServiceImpl&lt;/p&gt;</span></span><br><span class="line"><span class="comment"> * &lt;p&gt;Description: 认证类&lt;/p&gt;</span></span><br><span class="line"><span class="comment"> * &lt;p&gt;Company: www.itcast.cn&lt;/p&gt; </span></span><br><span class="line"><span class="comment"> * <span class="doctag">@version</span> 1.0</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserDetailsServiceImpl</span> <span class="keyword">implements</span> <span class="title">UserDetailsService</span> </span>&#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">	<span class="keyword">private</span> SellerService sellerService;</span><br><span class="line">	</span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setSellerService</span><span class="params">(SellerService sellerService)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">this</span>.sellerService = sellerService;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> UserDetails <span class="title">loadUserByUsername</span><span class="params">(String username)</span> <span class="keyword">throws</span> UsernameNotFoundException </span>&#123;</span><br><span class="line">		<span class="comment">// TODO Auto-generated method stub</span></span><br><span class="line">		System.out.println(<span class="string">"经过了....UserDetailsServiceImpl"</span>);</span><br><span class="line"></span><br><span class="line">		<span class="comment">//构建角色列表</span></span><br><span class="line">		Collection&lt;GrantedAuthority&gt; grantedAuthority = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">		grantedAuthority.add(<span class="keyword">new</span> SimpleGrantedAuthority(<span class="string">"ROLE_SELLER"</span>));</span><br><span class="line">		</span><br><span class="line">		TbSeller seller = sellerService.findOne(username);</span><br><span class="line">		<span class="keyword">if</span>(seller != <span class="keyword">null</span> &amp;&amp;  TestEnum.OK.getValue().equals(seller.getStatus()))&#123;</span><br><span class="line">			<span class="keyword">return</span> <span class="keyword">new</span> User(username,seller.getPassword(),grantedAuthority);</span><br><span class="line">		&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">			<span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div>
<ul>
<li><p><csrf disabled="true">关闭跨域请求的限制</csrf></p>
</li>
<li><p><logout>退出登录</logout></p>
<p>默认退出地址为：/logout</p>
<p>logout-url ：用于自定义退出地址</p>
<p>logout-success-url：用于自定义成功后跳转的页面，默认登陆页面</p>
</li>
</ul>
<h3 id="1-3bcrypt加密"><a href="#1-3bcrypt加密" class="headerlink" title="1.3bcrypt加密"></a>1.3bcrypt加密</h3><p>特点：自动加盐</p>
<ul>
<li>存储密码时加密</li>
</ul>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="JAVA"><figure class="iseeu highlight /java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">BCryptPasswordEncoder passwordEncoder = <span class="keyword">new</span> BCryptPasswordEncoder();</span><br><span class="line">String password = passwordEncoder.encode(seller.getPassword());</span><br></pre></td></tr></table></figure></div>
<p>登录密码加密，需要配置</p>
<div class="highlight-box" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="XML"><figure class="iseeu highlight /xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">beans:bean</span> <span class="attr">id</span>=<span class="string">"bcryptPasswordEncoder"</span> <span class="attr">class</span>=<span class="string">"org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"</span>&gt;</span><span class="tag">&lt;/<span class="name">beans:bean</span>&gt;</span></span><br></pre></td></tr></table></figure></div>

      
    </div>
    
      <footer class="article-footer">
        完
      </footer>
    
  </div>
  
    
<nav id="article-nav">
  <div class="article-nav-block">
    
      <a href="/2019/01/27/hello-world/" id="article-nav-newer" class="article-nav-link-wrap">
        <strong class="article-nav-caption"></strong>
        <div class="article-nav-title">
          
            Hello World
          
        </div>
      </a>
    
  </div>
  <div class="article-nav-block">
    
  </div>
</nav>

    
<div id="gitmentContainer"></div>
<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">
<script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script>
<script>
var gitment = new Gitment({
  owner: '',
  repo: '',
  oauth: {
    client_id: '',
    client_secret: '',
  },
})
gitment.render('gitmentContainer')
</script>

  
  
</article>
</section>
        <aside id="sidebar">
  
    <div class="widget-box">
  <div class="avatar-box">
    <img class="avatar" src="/images/guyue.jpg" title="图片来自网络">
    <h3 class="avatar-name">
      
        一路烟霞
      
    </h3>
    <p class="avatar-slogan">
      特别耐撕的小前端，资深的打酱油攻城狮。
    </p>
  </div>
</div>


  
    

  
    
  <div class="widget-box">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/品优购/">品优购</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-box">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/品优购/" style="font-size: 10px;">品优购</a>
    </div>
  </div>

  
    
  <div class="widget-box">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/01/">January 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/12/">December 2018</a></li></ul>
    </div>
  </div>

  
    
  <div class="widget-box">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2019/01/27/hello-world/">Hello World</a>
          </li>
        
          <li>
            <a href="/2018/12/08/1至7天内容复习/">1至7天内容复习</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
      </div>
      <footer id="footer">
  <div class="foot-box global-width">
    &copy; 2019 John Doe &nbsp;&nbsp;
    Powered by <a href="http://hexo.io/" target="_blank">Hexo</a><br>
    <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span id="busuanzi_container_site_pv">阁下是第<span id="busuanzi_value_site_pv"></span>个访客</span>
  </div>
</footer>
      <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

<script src="/js/jquery-2.0.3.min.js"></script>

  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



    </div>
    <nav id="mobile-nav" class="mobile-nav-box">
  <div class="mobile-nav-img mobile-nav-top"></div>
  
    <a href="/" class="mobile-nav-link">首页</a>
  
    <a href="/archives" class="mobile-nav-link">归档</a>
  
  <div class="mobile-nav-img  mobile-nav-bottom"></div>
</nav>    
  </div>
</body>
</html>